<?php


class ImmutableTimeSpan {
	private $value;
	
	public static function Make($days,$hours,$minutes,$seconds){
		return new ImmutableTimeSpan($days*self::SECONDS_IN_DAY + $hours*self::SECONDS_IN_HOUR + $minutes * self::SECONDS_IN_MINUTE + $seconds);
	}
	public function __construct($totalseconds=0){
		$this->value = $totalseconds;
	}
	
	const SECONDS_IN_DAY = 86400;
	const SECONDS_IN_HOUR = 3600;
	const SECONDS_IN_MINUTE = 60;
	
	public function GetDays(){ return intval($this->value/self::SECONDS_IN_DAY); }
	public function GetTotalHours(){ return intval($this->value/self::SECONDS_IN_HOUR); }
	public function GetTotalMinutes(){ return intval($this->value/self::SECONDS_IN_MINUTE); }
	public function GetTotalSeconds(){ return $this->value; }
	public function GetSign(){ return $this->value < 0 ? -1 : 1; }
	public function GetHours(){ return $this->GetSign() * intval((abs($this->value) % self::SECONDS_IN_DAY) / self::SECONDS_IN_HOUR); }
	public function GetMinutes(){ return $this->GetSign() * intval((abs($this->value) % self::SECONDS_IN_HOUR) / self::SECONDS_IN_MINUTE); }
	public function GetSeconds(){ return $this->GetSign() * (abs($this->value) % self::SECONDS_IN_MINUTE); }
	
	public function AsInt(){
		return $this->value;
	}
}
?>
